<template>
  <div class="monitor-schedule-table">
    <tag-content-header search refresh setting @toolFun="toolFun" :settingData="columns">
      <template #title>
        <span class="title-text">日志</span>
      </template>
    </tag-content-header>

    <tag-table
      ref="table"
      @refresh="getList"
      :data="dataList"
      :loading="loading"
      :columns="columns"
      :params="params"
      :total="totalSize"
    >
      <template #operation="{ scope }">
        <div class="operation-button-box">
          <el-tooltip effect="dark" content="查看日志" placement="top" :enterable="false">
            <icon-svg name="iconPreview" class="svg-view" @click.native="handleLog(scope.row)"></icon-svg>
          </el-tooltip>
          <el-tooltip effect="dark" content="下载日志" placement="top" :enterable="false">
            <icon-svg name="iconDownload" class="svg-edit" @click.native="handleDownload(scope.row)"></icon-svg>
          </el-tooltip>
        </div>
      </template>
    </tag-table>
    <log-dialog ref="logDialog"></log-dialog>
  </div>
</template>

<script>
import logDialog from './log-dialog'
export default {
  components: {
    logDialog
  },
  data() {
    return {
      dataList: [],
      loading: false,
      columns: [
        {
          show: true,
          label: '日志名称',
          prop: 'logNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '日志大小',
          prop: 'logSize',
          align: 'center'
        },
        {
          show: true,
          label: '日志类型',
          prop: 'logType',
          dict: '$log_status',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '日志时间',
          prop: 'logTime',
          width: 180,
          align: 'center'
        },
        {
          show: true,
          label: '操作',
          prop: 'operation',
          align: 'center',
          width: 160
        }
      ],
      params: {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      },
      totalSize: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.$ajax({
        url: this.$ajax.setUrl('tagLog/pageList'),
        method: 'get',
        params: this.$ajax.setParams(this.params)
      }).then(({ data }) => {
        if (data && data.code === '0') {
          if (data.data.currentPageNum === this.params.currentPageNum) {
            this.dataList = data.data.records
            this.totalSize = data.data.totalSize
          }
          let maxPageNum = Math.ceil(data.data.totalSize / this.params.pageSize) || 1
          if (this.params.currentPageNum > maxPageNum) {
            this.params.currentPageNum = maxPageNum
            this.getList()
          }
        } else {
          this.$message.error(data.data || data.msg)
        }
        this.loading = false
      })
    },
    toolFun(operation) {
      switch (operation) {
        case 'search':
          // 搜索动作
          this.$refs['table'].searchToggle()
          break
        case 'refresh':
          // 刷新动作
          this.$emit('refresh')
          this.getList()
          break
      }
    },
    handleDownload(item) {
      this.$utils.downloadCustomFile('tagLog/download', {
        logNm: item.logNm
      })
    },
    handleLog(item) {
      this.$refs.logDialog.showDialog(item.logNm)
    }
  }
}
</script>

<style lang="scss"></style>
